﻿using Coding4Fun.Lockscreen.Core.Models;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace Coding4Fun.Lockscreen.Mobile
{
    public class CentralBindingPoint : INotifyPropertyChanged
    {
        static CentralBindingPoint instance = null;
        static readonly object padlock = new object();

        public CentralBindingPoint()
        {
            Categories = new ObservableCollection<Category>();
            CustomCategories = new ObservableCollection<Category>();
        }

        public static CentralBindingPoint Instance
        {
            get
            {
                lock (padlock)
                {
                    if (instance == null)
                    {
                        instance = new CentralBindingPoint();
                    }
                    return instance;
                }
            }
        }

        private ObservableCollection<Category> _categories;
        public ObservableCollection<Category> Categories
        {
            get
            {
                return _categories;
            }
            set
            {
                if (_categories != value)
                {
                    _categories = value;
                    NotifyPropertyChanged("Categories");
                }
            }
        }

        private ObservableCollection<Category> _customCategories;
        public ObservableCollection<Category> CustomCategories
        {
            get
            {
                return _customCategories;
            }
            set
            {
                if (_customCategories != value)
                {
                    _customCategories = value;
                    NotifyPropertyChanged("CustomCategories");
                }
            }
        }

        private Category _currentCategory;
        public Category CurrentCategory
        {
            get
            {
                return _currentCategory;
            }
            set
            {
                if (_currentCategory != value)
                {
                    _currentCategory = value;
                    NotifyPropertyChanged("CurrentCategory");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(
                    () =>
                    {
                        PropertyChanged(this, new PropertyChangedEventArgs(info));
                    });
            }
        }
    }
}
